package models;


import org.junit.Test;
import siena.Id;
import siena.Index;
import siena.Model;
import siena.Query;

import java.util.ArrayList;
import java.util.List;

public class Evaluation extends Model{

    public enum UserEvaluation {NONE, CORRECT, INVALID}

    public UserEvaluation userEvaluation = UserEvaluation.NONE;

    @Id
    public Long id;

    @Index("game_index")
    public Game game;

    public Long cardId;

    public Evaluation(Game game, Card card) {
        this.game = game;
        this.cardId = card.getId();
    }

    private static Query<Evaluation> all() {
        return Model.all(Evaluation.class);
    }

    public static Evaluation findById(Long id) {
        return all().filter("id", id).get();
    }

    public static List<Evaluation> findAll() {
        return all().fetch();
    }


    public static List<Evaluation> findByGame(Game game) {
        return all().filter("game", game).fetch();
    }


    public static List<Card> findCardsByGame(Game game) {
        List<Evaluation> list = findByGame(game);
        ArrayList<Card> cards = new ArrayList<Card>();
        for (Evaluation evaluation : list) {
                cards.add(Card.findById( evaluation.cardId));
        }
        return cards;
    }


    public Card getCard() {
        return Card.findById(cardId);
    }

    @Override
    public String toString() {
        return "Evaluation{" +
                "userEvaluation=" + userEvaluation +
                ", id=" + id +
                ", game=" + game +
                ", cardId=" + cardId +
                '}';
    }

}
